package com.itheima;
import com.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;
/*
1.创建一个Student类
2创建集合对象
3键盘录入
4创建学生对象 吧键盘录入的数据赋值给学生对象
5往集合添加学生对象
6遍历集合 采用遍历可是实现
 */
public class test {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student stu1 = getStudent();
        Student stu2 = getStudent();
        Student stu3 = getStudent();
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.getName()+"...."+stu.getAge());
        }
    }

    public static Student getStudent() {
        //3键盘录入开门
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学生姓名:");
        String name = sc.next();
        System.out.println("请输入学生年龄:");
        int age = sc.nextInt();
        Student stu = new Student(name, age);
        return stu;
    }
}
